package org.display.graphic.line
{
	import flash.display.*;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import mx.flash.UIMovieClip;
	
	import org.utils.*;

	public class LineBase extends UIMovieClip
	{
		public var p1:Point=new Point(0,0)
		public var p2:Point=new Point(50,0)
	
		public var linecolor:uint=0x000000
		public var linethick:int=1
			
		public var square1:Sprite
		public var square2:Sprite	
		
		public var line:Sprite
		public var rot:Sprite
		
		private var selectSquare:Sprite
		
		public function LineBase()
		{
			p1=new Point(0,0)
			p2=new Point(50,0)	
				
			square1=DrawShape.diamond(linethick,linecolor,new Point(-5,-5),new Point(5,-5),new Point(5,5),new Point(-5,5),0.2)
			
			square2=DrawShape.diamond(linethick,linecolor,new Point(-5,-5),new Point(5,-5),new Point(5,5),new Point(-5,5),0.2)
				
			square1.x=p1.x
			square1.y=p1.y
				
			square2.x=p2.x
			square2.y=p2.y
				
			addChild(square1)
			addChild(square2)
				
			square1.addEventListener(MouseEvent.MOUSE_DOWN,mouseEvent)
			square2.addEventListener(MouseEvent.MOUSE_DOWN,mouseEvent)
				
		}
		
		function mouseEvent(e:MouseEvent){
			
			
			
			switch(e.type){
				
				case MouseEvent.MOUSE_DOWN:
					selectSquare=e.currentTarget as Sprite
					
					selectSquare.startDrag()
					stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseEvent)
					stage.addEventListener(MouseEvent.MOUSE_UP,mouseEvent)
					break
				
				case MouseEvent.MOUSE_MOVE:

					if(selectSquare==square1){
						p1.x=square1.x
						p1.y=square1.y
					}else if(selectSquare==square2){
						p2.x=square2.x
						p2.y=square2.y
					}
					redraw()

					break
				
				case MouseEvent.MOUSE_UP:
					square1.stopDrag()
					square2.stopDrag()
					stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseEvent)
					stage.removeEventListener(MouseEvent.MOUSE_UP,mouseEvent)
					break
			}
				
		}
		
		
		protected function redraw(){
		
		
		
		
		
		}
		
	}
}